home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / artAttrCreateMenuItems.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.4 KB  |  216 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. //    This file contains the MEL script to create the Paintable Attribute Menu
  19. //////////////////////////////////////////////////////////////////////////////
  20. global proc artAttrCreateMenuItems(
  21.     string    $parent,
  22.     string    $paintAttr
  23. )
  24. //
  25. //    Description:
  26. //         Creates a menu that shows all the paintable attributes.
  27. // 
  28. //    NOTE: paintAttr are sorted by the paintable node type.
  29. // 
  30. {
  31.     string  $artCommand = "artAttrCtx";
  32.  
  33.     string $paintableItems[];
  34.     tokenize( $paintAttr, " ", $paintableItems );
  35.  
  36.     int $size = size($paintableItems);
  37.     if ( $size == 0 )
  38.         return;  
  39.  
  40.      string    $menu, $menuLabel, $nodeMenuLabel; 
  41.     string  $attrName;
  42.  
  43.     string    $buffer[];
  44.     int        $i, $j;
  45.     
  46.     // Submenu counters.
  47.     int $setParentCount = 0;
  48.     int $menuItemCount  = 0;
  49.     for( $i = 0; $i < $size; $i++ ) {
  50.         if ( "" == $paintableItems[$i] ) 
  51.             continue;
  52.  
  53.         tokenize( $paintableItems[$i], ".", $buffer );
  54.     
  55.         // Create a paintable node submenu 
  56.         // if necessary.
  57.         if ( $buffer[0] != $nodeMenuLabel ) {
  58.             // Get back to the proper parent widget. 
  59.             for ($j = 0; $j < $setParentCount; $j++ ) {
  60.                 setParent ..;
  61.             }
  62.         
  63.             // Reset the submenu counters.
  64.             $setParentCount = 0;
  65.             $menuItemCount  = 0;
  66.  
  67.             // End the previous node subMenu.
  68.             if ( $i > 0 ) {
  69.                 setParent -m $parent;
  70.             }
  71.  
  72.             // Start a new node Menu;
  73.             $nodeMenuLabel = $buffer[0];
  74.             menuItem -subMenu true -l $nodeMenuLabel;
  75.         }
  76.  
  77.         if ( $menuItemCount == 30 ) {
  78.             // If there are more than 30 paintable nodes
  79.             // we need to split the menu into submenus 
  80.             // - otherwise it does not fit on the 
  81.             // screen.
  82.             menuItem -subMenu true -l "more ... ";
  83.             $setParentCount ++;
  84.  
  85.             $menuItemCount = 0;
  86.         }
  87.  
  88.         $menuLabel = $buffer[1] + "-" + $buffer[2];
  89.         string $arribute = $buffer[0] + "." + $buffer[1] + "." + $buffer[2];
  90.  
  91.         $menu = `menuItem -l $menuLabel`;
  92.         menuItem -e 
  93.             -c ("artSetToolAndSelectAttr( \"" + $artCommand + "\", \"" + $arribute + "\" )")
  94.         $menu;
  95.  
  96.         $menuItemCount ++;
  97.     } 
  98.  
  99.     // Get back to the proper parent widget. 
  100.     for ($i = 0; $i<$setParentCount; $i++ ) {
  101.         setParent ..;
  102.     }
  103.     setParent -m $parent;
  104. }
  105.  
  106.  
  107. global proc artSetToolAndSelectAttr(
  108.     string    $artCommand,
  109.     string     $attribute
  110. )
  111. //
  112. //    Description:
  113. //        Set a new tool if require and select an initial attribute.
  114. //
  115. {
  116.     source "artAttrCallback.mel";
  117.  
  118.     string  $currentContext = `currentCtx`;
  119.     string  $currTool = `contextInfo -c $currentContext`;
  120.  
  121.     // Check if we are in the right tool.
  122.     string $buf[];
  123.     tokenize( $attribute, ".", $buf );
  124.     if ( size($buf) < 3 )
  125.        return;
  126.  
  127.     string $paintableNodeType = $buf[0];
  128.     string $paintableNodeName = $buf[1];
  129.     string $paintableAttribute = $buf[2];
  130.  
  131.     if ( $paintableNodeType == "skinCluster" ) {
  132.         // Check if this is skin paint weight tool. 
  133.         if ( $currTool != "artAttrSkin" ) {
  134.             // Set the Skin Paint Weight tool.
  135.             artAttrSkinToolScript( 4 );
  136.         }
  137.     } else if ( $paintableNodeType == "mesh" && 
  138.         ($paintableAttribute == "vertexColorRGB" || $paintableAttribute == "vertexFaceColorRGB" ) ) {
  139.         // Check if this is paint vertex color tool. 
  140.         if ( $currTool != "artAttrColorPerVertex" ) {
  141.             if ( $paintableAttribute == "vertexColorRGB" ) {
  142.                 // Set the Paint Vertex Color itool.
  143.                 artAttrColorPerVertexToolScript( 5 );
  144.             } else {
  145.                 artAttrColorPerVertexToolScript( 6 );
  146.             }
  147.         }
  148.     } else {
  149.         // You can only paint weights for polyReduce on a mesh node
  150.         // upstream of the polyReduce node. This is because painting weights
  151.         // on the mesh being reduced changes the topology and scrambles the 
  152.         // painted vertices. 
  153.         // So, here, we march up stream from the reduce node until
  154.         // a valid mesh is found, and set that as the mesh being painted.
  155.         //
  156.         // The recommended way for you to use paint weights is to invoke the 
  157.         // command with the replaceOriginal flag off (or the Keep Original 
  158.         // option checked).
  159.         //
  160.         if ( $paintableNodeType == "polyReduce" ) {
  161.             // get all upstream nodes
  162.             //
  163.             string $upstreamNodes[] = `listHistory $paintableNodeName`;
  164.             int $i = 0;
  165.             string $node = "";
  166.             int $found = false;
  167.             // march through upstream nodes looking for a valid mesh
  168.             //
  169.             for ($node in $upstreamNodes ) {
  170.                 string $nodeType = `nodeType $node`;
  171.  
  172.                 // only poly meshes are valid for polyReduce
  173.                 //
  174.                 if ( $nodeType == "mesh" ) {
  175.                     int $isVisible = `getAttr( $node + ".visibility" )`;
  176.                     int $isIntermediate = `getAttr( $node + ".intermediateObject" )`;
  177.                     int $isTemplated = `getAttr( $node + ".template" )`;
  178.  
  179.                     // the node must be visible and not intermediate
  180.                     //
  181.                     if ( $isVisible && !$isIntermediate ) {
  182.                         // Un-template an otherwise valid node (so we can select it)
  183.                         //
  184.                         if ( $isTemplated ) {
  185.                             setAttr( $node + ".template", false );
  186.                             warning($paintableNodeName + " can not accept templated nodes as input. Un-templating " + $node + "." );
  187.                         }
  188.                         $found = true;
  189.                         break;
  190.                     }
  191.                 }
  192.             }
  193.             // No valid upstream meshes.
  194.             //
  195.             if ( !$found ) {
  196.                 string $errorMsg = "Can't paint weights on the reduced mesh.\n";
  197.                 $errorMsg += "// Turn Keep Original on in the Reduce options and";
  198.                 $errorMsg += " paint weights on the original.";
  199.                 error( $errorMsg );
  200.                 return;
  201.             } else {
  202.                 // found a valid mesh. Pick it as the mesh being painted.
  203.                 //
  204.                 select $node;
  205.             }
  206.         }
  207.         if ( $currTool != "artAttr" ) {
  208.             // Set the general Attribue Paint Tool.
  209.             artAttrToolScript( 4, "" );
  210.         }
  211.     }
  212.     
  213.     // Set the selected attribute as paintable.
  214.     artAttrSelected( $artCommand, $attribute );
  215. }
  216.